package org.swingplus.core.widget;

import org.swingplus.core.utils.IconUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.swingplus.core.annotation.Dimension;
import org.swingplus.core.annotation.css.*;
import org.swingplus.core.annotation.layout.Layout;
import org.swingplus.core.annotation.widget.Button;
import org.swingplus.core.annotation.widget.*;
import org.swingplus.core.annotation.widget.Frame;
import org.swingplus.core.annotation.widget.Label;
import org.swingplus.core.annotation.widget.Panel;
import org.swingplus.core.annotation.widget.TextField;
import org.swingplus.core.annotation.widget.TrayIcon;
import org.swingplus.core.utils.FontUtil;

import javax.swing.*;
import javax.swing.border.LineBorder;

import java.awt.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class WidgetActvity {

    private static final Logger logger = LoggerFactory.getLogger(WidgetActvity.class);

    public static void onCreate(Object clazz, Field field) {

        initialize(clazz, field);

    }

    public static void initialize(Object clazz, Field field) {

        // 默认属性
        defaultAttribute();
        // 指定属性
        specifyAttribute(clazz, field);
        // 自定义属性
        customerAttribute();

    }


    private static void customerAttribute() {
        // TODO Auto-generated method stub

    }

    public static void specifyAttribute(Object clazz, String methodName, Annotation[] annotations) {
        for (int i = 0; i < annotations.length; i++) {
            Annotation annotation = annotations[i];
//			logger.info(annotation.annotationType().getSimpleName());
            if (annotation.annotationType() == Frame.class) {
                Frame frame = (Frame) annotation;
                boolean undecorated = frame.undecorated();
                logger.info("setUndecorated,{}", undecorated);
                Method method = null;
                try {
                    method = clazz.getClass().getMethod("setUndecorated", new Class[]{boolean.class});
                    method.invoke(clazz, undecorated);
                } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            } else if (annotation.annotationType() == Dimension.class) {
                Dimension anno = (Dimension) annotation;
                int windowWidth = anno.windowWidth();
                int windowHeight = anno.windowHeight();
                java.awt.Dimension jDimension = new java.awt.Dimension();
                jDimension.setSize(windowWidth, windowHeight);
                logger.info("setMinimumSize,{},{}", windowWidth, windowHeight);
                logger.info("setMaximumSize,{},{}", windowWidth, windowHeight);
                boolean centerScreen = anno.centerScreen();
                Method method = null;
                try {
                    if (centerScreen) {
                        logger.info("centerScreen,{},{}", windowWidth, windowHeight);
                        Toolkit tk = Toolkit.getDefaultToolkit();
                        method = clazz.getClass().getMethod("setLocation", new Class[]{int.class, int.class});
                        method.invoke(clazz, (tk.getScreenSize().width - windowWidth) / 2, (tk.getScreenSize().height - windowHeight) / 2);
                    }
                    method = clazz.getClass().getMethod("setMinimumSize", new Class[]{java.awt.Dimension.class});
                    method.invoke(clazz, jDimension);
                    method = clazz.getClass().getMethod("setMaximumSize", new Class[]{java.awt.Dimension.class});
                    method.invoke(clazz, jDimension);
                } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }else if (annotation.annotationType() == MinimumSize.class) {
                MinimumSize anno = (MinimumSize) annotation;
                int windowWidth = anno.windowWidth();
                int windowHeight = anno.windowHeight();
                java.awt.Dimension jDimension = new java.awt.Dimension();
                jDimension.setSize(windowWidth, windowHeight);
                logger.info("setMinimumSize,{},{}", windowWidth, windowHeight);
                Method method = null;
                try {
                    method = clazz.getClass().getMethod("setMinimumSize", new Class[]{java.awt.Dimension.class});
                    method.invoke(clazz, jDimension);
                } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }else if (annotation.annotationType() == MaximumSize.class) {
                MaximumSize anno = (MaximumSize) annotation;
                int windowWidth = anno.windowWidth();
                int windowHeight = anno.windowHeight();
                java.awt.Dimension jDimension = new java.awt.Dimension();
                jDimension.setSize(windowWidth, windowHeight);
                logger.info("setMaximumSize,{},{}", windowWidth, windowHeight);

                Method method = null;
                try {
                    method = clazz.getClass().getMethod("setMaximumSize", new Class[]{java.awt.Dimension.class});
                    method.invoke(clazz, jDimension);
                } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }


    }

    private static void specifyAttribute(Object clazz, Field field) {
        boolean fieldHasAnno = field.isAnnotationPresent(Panel.class);
        if (fieldHasAnno) {
            Panel fieldAnno = field.getAnnotation(Panel.class);
            int cursor = fieldAnno.cursor();
            Method method = null;
            try {
                method = clazz.getClass().getMethod("setCursor", new Class[]{Cursor.class});
                method.invoke(clazz, new Cursor(cursor));
            } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        fieldHasAnno = field.isAnnotationPresent(ProgressBar.class);
        if (fieldHasAnno) {
            ProgressBar fieldAnno = field.getAnnotation(ProgressBar.class);
            int cursor = fieldAnno.cursor();
            Method method = null;
            try {
                method = clazz.getClass().getMethod("setCursor", new Class[]{Cursor.class});
                method.invoke(clazz, new Cursor(cursor));
            } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        fieldHasAnno = field.isAnnotationPresent(Table.class);
        if (fieldHasAnno) {
            Table fieldAnno = field.getAnnotation(Table.class);
            int cursor = fieldAnno.cursor();
            Method method = null;
            try {
                method = clazz.getClass().getMethod("setCursor", new Class[]{Cursor.class});
                method.invoke(clazz, new Cursor(cursor));
            } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        fieldHasAnno = field.isAnnotationPresent(Frame.class);
        if (fieldHasAnno) {
            Frame fieldAnno = field.getAnnotation(Frame.class);
            int cursor = fieldAnno.cursor();
            Method method = null;
            try {
                method = clazz.getClass().getMethod("setCursor", new Class[]{Cursor.class});
                method.invoke(clazz, new Cursor(cursor));
            } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        // 输出注解属性
//		int age = field.age();
//		String[] hobby = fieldAnno.hobby();
//		String type = fieldAnno.type();
//		System.out.println(
//				field.getName() + " age = " + age + ", hobby = " + Arrays.asList(hobby).toString() + " type = " + type);
//	PropertyManageUtil.setProperty(field,fieldAnno.hobby());PropertyManageUtil.setProperty(field,fieldAnno.hobby());PropertyManageUtil.setProperty(field,fieldAnno.hobby());PropertyManageUtil.setProperty(field,fieldAnno.hobby());

    }

    private static void specifyAttributeTest(Object clazz, Field field) {
        boolean fieldHasAnno = field.isAnnotationPresent(Panel.class);
        if (fieldHasAnno) {
            Panel fieldAnno = field.getAnnotation(Panel.class);
            int cursor = fieldAnno.cursor();
            Method method = null;
            try {
                method = clazz.getClass().getMethod("setCursor", new Class[]{Cursor.class});
                method.invoke(clazz, new Cursor(cursor));
            } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    private static void specifyAttributeTest(Object instance, Field field, Class clazz) {
        boolean fieldHasAnno = field.isAnnotationPresent(Panel.class);
        if (fieldHasAnno) {
            Panel fieldAnno = field.getAnnotation(Panel.class);
            int cursor = fieldAnno.cursor();
            Method method = null;
            try {
                method = instance.getClass().getMethod("setCursor", new Class[]{Cursor.class});
                method.invoke(clazz, new Cursor(cursor));
            } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }


    private static void defaultAttribute() {
        // TODO Auto-generated method stub

    }

    public static void specifyAttribute(Object instance, Field field, Annotation[] annotations) {
        for (Annotation annotation : annotations) {
            specifyAttribute(instance, field, annotation.annotationType());
        }
    }

    private static void specifyAttribute(Object instance, Field field, Class<? extends Annotation> annotationType) {
        boolean fieldHasAnno = field.isAnnotationPresent(annotationType);
        if (fieldHasAnno) {
            String annotationTypeName = annotationType.getSimpleName();
            Object fieldObj = null;
            try {
                field.setAccessible(true);
                fieldObj = field.get(instance);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            if (annotationTypeName.equals("Panel")) {
                Panel fieldAnno = (Panel) field.getAnnotation(annotationType);
                int cursor = fieldAnno.cursor();
                boolean opaque=fieldAnno.opaque();

                Method method = null;
                field.setAccessible(true);
                try {
                    method = fieldObj.getClass().getMethod("setCursor", new Class[]{Cursor.class});
                    method.invoke(fieldObj, new Cursor(cursor));

                    //组件透明度
                    method = fieldObj.getClass().getMethod("setOpaque", new Class[]{boolean.class});
                    method.invoke(fieldObj, opaque);

                } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                field.setAccessible(false);
            } else if (annotationTypeName.equals("Button")) {

                Button fieldAnno = (Button) field.getAnnotation(annotationType);
                int cursor = fieldAnno.cursor();
                String text = fieldAnno.text();
                int fontSize = fieldAnno.fontSize();
                int[] foreground = fieldAnno.foreground();
                Method method = null;
                field.setAccessible(true);
                try {
                    method = fieldObj.getClass().getMethod("setCursor", new Class[]{Cursor.class});
                    method.invoke(fieldObj, new Cursor(cursor));

                    method = fieldObj.getClass().getMethod("setText", new Class[]{String.class});
                    method.invoke(field.get(instance), text);

                    method = fieldObj.getClass().getMethod("setFont", new Class[]{Font.class});
                    method.invoke(fieldObj, FontUtil.getDefaultFont(fontSize));
                    method = fieldObj.getClass().getMethod("setForeground", new Class[]{Color.class});
                    method.invoke(fieldObj, new Color(foreground[0], foreground[1], foreground[2]));


                } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                field.setAccessible(false);
            } else if (annotationTypeName.equals("TextField")) {
                TextField fieldAnno = (TextField) field.getAnnotation(annotationType);
                int cursor = fieldAnno.cursor();
                String text = fieldAnno.text();
                int fontSize = fieldAnno.fontSize();
                String placeholder = fieldAnno.placeholder();
                int[] foreground = fieldAnno.foreground();
                Method method = null;
                field.setAccessible(true);
                try {

                    method = fieldObj.getClass().getMethod("setCursor", new Class[]{Cursor.class});
                    method.invoke(fieldObj, new Cursor(cursor));

                    method = fieldObj.getClass().getMethod("setText", new Class[]{String.class});
                    method.invoke(field.get(instance), text);

                    method = fieldObj.getClass().getMethod("setFont", new Class[]{Font.class});
                    method.invoke(fieldObj, FontUtil.getDefaultFont(fontSize));
                    method = fieldObj.getClass().getMethod("setPlaceholder", new Class[]{String.class});
                    method.invoke(fieldObj, placeholder);

                    method = fieldObj.getClass().getMethod("setForeground", new Class[]{Color.class});
                    method.invoke(fieldObj, new Color(foreground[0], foreground[1], foreground[2]));
                } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                field.setAccessible(false);
            } else if (annotationTypeName.equals("Password")) {
                Password fieldAnno = (Password) field.getAnnotation(annotationType);
                int cursor = fieldAnno.cursor();
                String text = fieldAnno.text();
                int fontSize = fieldAnno.fontSize();
                String placeholder = fieldAnno.placeholder();
                int[] foreground = fieldAnno.foreground();
                Method method = null;
                field.setAccessible(true);
                try {

                    method = fieldObj.getClass().getMethod("setCursor", new Class[]{Cursor.class});
                    method.invoke(fieldObj, new Cursor(cursor));

                    method = fieldObj.getClass().getMethod("setText", new Class[]{String.class});
                    method.invoke(field.get(instance), text);

                    method = fieldObj.getClass().getMethod("setFont", new Class[]{Font.class});
                    method.invoke(fieldObj, FontUtil.getDefaultFont(fontSize));
                    method = fieldObj.getClass().getMethod("setPlaceholder", new Class[]{String.class});
                    method.invoke(fieldObj, placeholder);
                    method = fieldObj.getClass().getMethod("setForeground", new Class[]{Color.class});
                    method.invoke(fieldObj, new Color(foreground[0], foreground[1], foreground[2]));

                } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                field.setAccessible(false);
            } else if (annotationTypeName.equals("Table")) {
                Table fieldAnno = (Table) field.getAnnotation(annotationType);
                int cursor = fieldAnno.cursor();
                Method method = null;
                try {
                    method = fieldObj.getClass().getMethod("setCursor", new Class[]{Cursor.class});
                    method.invoke(fieldObj, new Cursor(cursor));
                } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }


            } else if (annotationTypeName.equals("CheckBox")) {
                CheckBox fieldAnno = (CheckBox) field.getAnnotation(annotationType);
                int cursor = fieldAnno.cursor();
                String text = fieldAnno.text();
                boolean selected = fieldAnno.selected();
                int fontSize = fieldAnno.fontSize();
                Method method = null;
                field.setAccessible(true);
                try {
                    method = fieldObj.getClass().getMethod("setCursor", new Class[]{Cursor.class});
                    method.invoke(fieldObj, new Cursor(cursor));


                    method = fieldObj.getClass().getMethod("setText", new Class[]{String.class});
                    method.invoke(fieldObj, text);


                    method = fieldObj.getClass().getMethod("setSelected", new Class[]{boolean.class});
                    method.invoke(fieldObj, selected);

                    method = fieldObj.getClass().getMethod("setFont", new Class[]{Font.class});
                    method.invoke(fieldObj, FontUtil.getDefaultFont(fontSize));
                } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    e.printStackTrace();
                }
                field.setAccessible(false);

            } else if (annotationTypeName.equals("Label")) {
                Label fieldAnno = (Label) field.getAnnotation(annotationType);
                int cursor = fieldAnno.cursor();
                String text = fieldAnno.text();
                int fontSize = fieldAnno.fontSize();
                int horizontalAlignment = fieldAnno.horizontalAlignment();
                boolean visible = fieldAnno.visible();
                int[] foreground = fieldAnno.foreground();
                boolean isIcon = fieldAnno.isIcon();
                String path = fieldAnno.path();
                Method method = null;
                field.setAccessible(true);
                try {
                    method = fieldObj.getClass().getMethod("setCursor", new Class[]{Cursor.class});
                    method.invoke(fieldObj, new Cursor(cursor));
                    method = fieldObj.getClass().getMethod("setText", new Class[]{String.class});
                    method.invoke(fieldObj, text);
                    method = fieldObj.getClass().getMethod("setFont", new Class[]{Font.class});
                    method.invoke(fieldObj, FontUtil.getDefaultFont(fontSize));
                    method = fieldObj.getClass().getMethod("setHorizontalAlignment", new Class[]{int.class});
                    method.invoke(fieldObj, horizontalAlignment);
                    method = fieldObj.getClass().getMethod("setVisible", new Class[]{boolean.class});
                    method.invoke(fieldObj, visible);
                    method = fieldObj.getClass().getMethod("setForeground", new Class[]{Color.class});
                    method.invoke(fieldObj, new Color(foreground[0], foreground[1], foreground[2]));
                    if (isIcon) {
                        method = fieldObj.getClass().getMethod("setIcon", new Class[]{Icon.class});
                        method.invoke(fieldObj, IconUtil.getIcon(instance, path));
                    }
                } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                field.setAccessible(false);


            } else if (annotationTypeName.equals("ProgressBar")) {
                ProgressBar fieldAnno = (ProgressBar) field.getAnnotation(annotationType);
                int cursor = fieldAnno.cursor();
                Method method = null;
                try {
                    method = instance.getClass().getMethod("setCursor", new Class[]{Cursor.class});
                    method.invoke(instance, new Cursor(cursor));
                } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }


            } else if (annotationTypeName.equals("Password")) {
                Password fieldAnno = (Password) field.getAnnotation(annotationType);
                int cursor = fieldAnno.cursor();
                int[] foreground = fieldAnno.foreground();

                Method method = null;
                try {
                    method = instance.getClass().getMethod("setCursor", new Class[]{Cursor.class});
                    method.invoke(instance, new Cursor(cursor));
                    method = instance.getClass().getMethod("setForeground", new Class[]{Color.class});
                    method.invoke(instance, new Color(foreground[0], foreground[1], foreground[2]));

                } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }else if (annotationTypeName.equals("TrayIcon")) {
                TrayIcon fieldAnno = (TrayIcon) field.getAnnotation(annotationType);

                String setToolTip =fieldAnno.toolTip();
                Method method = null;
                try {
                    method = fieldObj.getClass().getMethod("setToolTip", new Class[]{String.class});
                    method.invoke(fieldObj, setToolTip);


                } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            	//TODO
            }else if (annotationTypeName.equals("Password")) {
            	//TODO
            }else if (annotationTypeName.equals("Password")) {
            	//TODO
            }else if (annotationTypeName.equals("Password")) {
            	//TODO
            }else if (annotationTypeName.equals("Password")) {
            	//TODO
            }else if (annotationTypeName.equals("Password")) {
            	//TODO
            }            
            else if (annotationTypeName.equals("Size")) {
                Size fieldAnno = (Size) field.getAnnotation(annotationType);


                int width = fieldAnno.width();
                int height = fieldAnno.height();
                java.awt.Dimension dimension=new java.awt.Dimension(width,height);
                Method method = null;
                field.setAccessible(true);
                try {

                    method = fieldObj.getClass().getMethod("setSize", new Class[]{java.awt.Dimension.class});
                    method.invoke(fieldObj, dimension);

                } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                field.setAccessible(false);
            }else if (annotationTypeName.equals("PreferredSize")) {
                PreferredSize fieldAnno = (PreferredSize) field.getAnnotation(annotationType);
                int width = fieldAnno.width();
                int height = fieldAnno.height();
                java.awt.Dimension dimension=new java.awt.Dimension(width,height);
                Method method = null;
                field.setAccessible(true);
                try {

                    method = fieldObj.getClass().getMethod("setPreferredSize", new Class[]{java.awt.Dimension.class});
                    method.invoke(fieldObj, dimension);

                } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                field.setAccessible(false);
            }else if (annotationTypeName.equals("Margin")) {
                Margin fieldAnno = (Margin) field.getAnnotation(annotationType);
                Insets insets=new Insets(fieldAnno.top(), fieldAnno.left(),fieldAnno.bottom() ,fieldAnno.right());
                Method method = null;
                field.setAccessible(true);
                try {

                    method = fieldObj.getClass().getMethod("setMargin", new Class[]{java.awt.Insets.class});
                    method.invoke(fieldObj, insets);

                } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                field.setAccessible(false);
            }else if (annotationTypeName.equals("Border")) {
            	Border fieldAnno = (Border) field.getAnnotation(annotationType);
            	Object lineBorder=null;
            	if (fieldAnno.border().getSimpleName()=="LineBorder") {		 
            		int[] color = fieldAnno.color();
            		lineBorder=new LineBorder(new Color(color[0],color[1],color[2]));
				}
                Method method = null;
                field.setAccessible(true);
                try {

                    method = fieldObj.getClass().getMethod("setBorder", new Class[]{javax.swing.border.Border.class});
                    method.invoke(fieldObj, lineBorder);
                } catch (NoSuchMethodException | SecurityException  | IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                field.setAccessible(false);
            }
            else if (annotationTypeName.equals("Layout")) {
            	Layout fieldAnno = (Layout) field.getAnnotation(annotationType);
                Method method = null;
                field.setAccessible(true);
                try {
                	LayoutManager ds=null;
                    Class layoutClass=fieldAnno.layout();
                    if(layoutClass==FlowLayout.class){
                        Constructor constructor=layoutClass.getConstructor(int.class,int.class,int.class);
                        ds=(FlowLayout) constructor.newInstance(fieldAnno.align(),fieldAnno.hgap(),fieldAnno.vgap());
                    }else if(layoutClass==CardLayout.class) {
                        Constructor constructor=layoutClass.getConstructor(int.class,int.class);
                        ds=(CardLayout) constructor.newInstance(fieldAnno.hgap(),fieldAnno.vgap());
                    }else if(layoutClass==BorderLayout.class) {
                        Constructor constructor=layoutClass.getConstructor(int.class,int.class);
                        ds=(BorderLayout) constructor.newInstance(fieldAnno.hgap(),fieldAnno.vgap());
                    }

                    else if(layoutClass==BoxLayout.class) {
                        Constructor constructor=layoutClass.getConstructor(Container.class,int.class);
                        ds=(FlowLayout) constructor.newInstance((Container)null,fieldAnno.axis());
                    }else if(layoutClass==java.awt.GridLayout.class) {
                        Constructor constructor=layoutClass.getConstructor(int.class,int.class,int.class,int.class);
                        ds=(FlowLayout) constructor.newInstance(fieldAnno.rows(),fieldAnno.cols(),fieldAnno.hgap(),fieldAnno.vgap());
                    }else if(layoutClass==java.awt.GridBagLayout.class) {
                        ds=(LayoutManager)fieldAnno.layout().newInstance();
                        //TODO 没发现有参构造的方法
//                        Constructor constructor=layoutClass.getConstructor(int.class,int.class,int.class,int.class);
//                        ds=(FlowLayout) constructor.newInstance(fieldAnno.rows(),fieldAnno.cols(),fieldAnno.hgap(),fieldAnno.vgap());
                    }else{
                        logger.info("设置默认布局");
                        ds=(LayoutManager)fieldAnno.layout().newInstance();
                    }
                    method = fieldObj.getClass().getMethod("setLayout", new Class[]{java.awt.LayoutManager.class});
                    method.invoke(fieldObj, ds);
                } catch (NoSuchMethodException | SecurityException  | IllegalArgumentException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
                    e.printStackTrace();
                }
                field.setAccessible(false);
            }else if (annotationTypeName.equals("Bounds")) {
                Bounds fieldAnno = (Bounds) field.getAnnotation(annotationType);
                Method method = null;
                field.setAccessible(true);
                try {
                    method = fieldObj.getClass().getMethod("setBounds", new Class[]{int.class,int.class,int.class,int.class});
                    method.invoke(fieldObj, fieldAnno.x(),fieldAnno.y(),fieldAnno.width(),fieldAnno.height());
                } catch (NoSuchMethodException | SecurityException  | IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
                    e.printStackTrace();
                }
                field.setAccessible(false);
            }
        }

    }

}
